<template>
  <base-breadcrumb title="科技成果详情" :breadcrumb="!isAudit">
    <div
      v-loading="loading"
      class="about-master-container"
    >
      <a-card>
        <title-name title="基础信息" />
        <a-form-model>
          <a-row>
            <a-col span="16">
              <a-form-model-item label="所属单位">
                <BaseInput disabled v-model="form.viewName" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
<!--            <a-col span="8">-->
<!--              <a-form-model-item label="项目名称">-->
<!--                <BaseInput disabled v-model="form.projectName" placeholder="请输入" />-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
          </a-row>
        </a-form-model>
      </a-card>
      <a-card v-if="Plan">
        <title-name title="科技管理计划信息" />
        <a-form-model>
          <a-row>
            <a-col span="8">
              <a-form-model-item label="成果名称">
                <BaseInput disabled v-model="Plan.planAchievementsName" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
            <a-col span="8">
              <a-form-model-item label="成果分类">
                <BaseInput disabled v-model="Plan.achievementsType" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
            <a-col span="8">
              <a-form-model-item label="成果等级">
                <BaseInput disabled v-model="Plan.planAchievementsLevel" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
            <a-col span="8">
              <a-form-model-item label="计划完成人">
                <a-tag>{{ Plan.planCompleteEmployee }}</a-tag>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="8">
              <a-form-model-item label="计划完成时间">
                <BaseInput disabled v-model="Plan.planCompleteDate" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
            <a-col span="8">
              <a-form-model-item label="计划附件">
                <file-link :file-list="Plan.fileArrays" />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-card>
      <a-card v-if="declare">
        <title-name title="科技成果申报信息" />
        <a-form-model>
          <a-row>
            <a-col span="8">
              <a-form-model-item label="成果名称">
                <BaseInput disabled v-model="declare.declareAchievementsName" placeholder="请输入" />
              </a-form-model-item>
            </a-col>

            <a-col span="8">
              <a-form-model-item label="成果分类">
                <BaseInput disabled v-model="declare.declareType" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
            <a-col span="8">
              <a-form-model-item label="成果等级">
                <BaseInput disabled v-model="declare.declareAchievementsLevel" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
            <a-col span="24">
              <a-form-model-item label="申报人">
                <a-tag v-for="item in declare.joinEmployee" :key="item.employeeName">
                  {{ item.employeeName }}
                </a-tag>
                <span v-if="!declare.joinEmployee || declare.joinEmployee.length == 0">无</span>
              </a-form-model-item>
            </a-col>
            <a-col span="8">
              <a-form-model-item label="申报日期">
                <BaseInput disabled v-model="declare.declareDate" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
            <a-col span="8">
              <a-form-model-item label="附件">
                <file-link :file-list="declare.fileArrays" />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-card>
      <a-card v-if="queryParam.id">
        <title-name title="科技成果完成情况" />
        <a-form-model>
          <a-row>
            <a-col span="8">
              <a-form-model-item
                label="完成状态"
                prop="completionStatus"
              >
                <a-select
                  v-model="queryParam.completionStatus"
                  disabled
                  placeholder="请选择"
                >
                  <a-select-option value="4">
                    获得
                  </a-select-option>
                  <a-select-option value="5">
                    未获得
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col span="8">
              <a-form-model-item
                label="完成成果名称"
                prop="completeAchievementsName"
              >
                <BaseInput
                  disabled
                  v-model.trim="queryParam.completeAchievementsName"
                  placeholder="请输入完成成果名称"
                />
              </a-form-model-item>
            </a-col>
            <a-col span="8">
              <a-form-model-item
                label="成果分类"
                prop="achievementsTypeId"
              >
                <a-select
                  disabled
                  v-model="queryParam.achievementsTypeId"
                  placeholder="请选择"
                  @change="getLevelList($event)"
                >
                  <a-select-option
                    v-for="item in ClassifyList"
                    :key="item.id"
                    :value="item.id"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col span="8" v-if="queryParam.achievementsTypeId == '683867596952571904'">  
              <a-form-model-item
                label="期刊类型"
              >
                <BaseInput disabled v-model="queryParam.periodicalTypeName" />
              </a-form-model-item>
            </a-col>
            <a-col span="8">
              <a-form-model-item
                label="成果等级"
                prop="completeAchievementsLevelId"
              >
                <a-select
                  disabled
                  v-model="queryParam.completeAchievementsLevelId"
                  placeholder="请选择"
                  @change="completeAchievementsLevelIdChange($event)"
                >
                  <a-select-option
                    v-for="item in LevelList"
                    :key="item.id"
                    :value="item.id"
                  >
                    {{ item.levelName }}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col span="16">
              <a-form-model-item
                label="完成人"
                prop="completeEmployee"
              >
                <a-tag
                  v-for="item in queryParam.completeEmployee"
                  :key="item.id"
                >
                  {{ item.name }}
                </a-tag>
                <span class="del_btn mr20">（按证书上面完成人顺序填写）</span>
              </a-form-model-item>
            </a-col>
            <a-col span="16">
              <a-form-model-item
                label="成果完成单位"
                prop="completeOrgDTOS"
              >
                <a-tag
                  v-for="item in queryParam.completeOrgDTOS"
                  :key="item.completeOrgId"
                >
                  {{ item.completeOrgName }}
                </a-tag>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="8">
              <a-form-model-item
                label="完成日期"
                prop="completeDate"
              >
                <a-date-picker
                  disabled
                  v-model="queryParam.completeDate"
                  type="date"
                  value-format="YYYY-MM-DD HH:mm:ss"
                />
              </a-form-model-item>
            </a-col>
            <a-col span="8">
              <a-form-model-item
                label="标引"
                prop="indexInfo"
              >
                <a-tree-select
                  multiple
                  disabled
                  :value="queryParam.indexInfo"
                  style="width: 100%"
                  :tree-data="indexInfoList"
                  :replaceFields="	{children:'children', title:'name', key:'id', value: 'id' }"
                  :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
                  placeholder="请选择"
                ></a-tree-select>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <template v-if="achievementsTypeName === '科技奖'">
              <a-col span="8">
                <a-form-model-item
                  prop="awardName"
                  label="授奖称号"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.awardName"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="awardDpt"
                  label="授奖单位"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.awardDpt"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <!-- <a-col span="8">
                <a-form-model-item prop="completeOrgName" label="成果完成单位">
                  <a-select v-model="queryParam.completeOrgName" placeholder="请选择">
                    <a-select-option :value="item.name" v-for="item in completeOrgList">{{ item.name }}</a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col> -->
              <a-col span="8">
                <a-form-model-item
                  label="证书编号"
                  prop="certificateCode"
                  :key="1"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.certificateCode"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
            </template>

            <!--                研发立项-->
            <template v-if="achievementsTypeName === '研发立项'">
              <a-col span="8">
                <a-form-model-item
                  prop="projectCode"
                  label="立项编号"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.projectCode"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item label="实施情况">
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.progressSituation"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="beginAndEndTime"
                  label="起始时间"
                >
                  <a-date-picker
                    disabled
                    v-model="queryParam.beginAndEndTime"
                    type="date"
                    value-format="YYYY-MM-DD HH:mm:ss"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="planDate"
                  label="计划验收时间"
                >
                  <a-date-picker
                    disabled
                    v-model="queryParam.planDate"
                    type="date"
                    value-format="YYYY-MM-DD HH:mm:ss"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item label="实际验收时间">
                  <a-date-picker
                    disabled
                    v-model="queryParam.factDate"
                    type="date"
                    value-format="YYYY-MM-DD HH:mm:ss"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="totalFee"
                  label="总经费（万）"
                >
                  <BaseInputNumber
                    disabled
                    :precision="6"
                    v-model="queryParam.totalFee"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="subsidizeFee"
                  label="资助经费（万）"
                >
                  <BaseInputNumber
                    disabled
                    :precision="6"
                    v-model.trim="queryParam.subsidizeFee"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="classPrincipalPeople"
                  label="课题负责人"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.classPrincipalPeople"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item label="证书编号" :key="2">
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.certificateCode"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item label="课题研发人员" :key="Date.now()">
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.classDiscoveryPeople"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
            </template>

            <!--                示范工程立项-->
            <template v-if="achievementsTypeName === '示范工程立项'">
              <a-col span="8">
                <a-form-model-item
                  prop="projectCode"
                  label="立项编号"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.projectCode"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item label="实施情况">
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.progressSituation"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item label="实施状态">
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.implementStatus"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="planDate"
                  label="计划验收时间"
                >
                  <a-date-picker
                    disabled
                    v-model="queryParam.planDate"
                    type="date"
                    value-format="YYYY-MM-DD HH:mm:ss"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item label="实际验收时间">
                  <a-date-picker
                    disabled
                    v-model="queryParam.factDate"
                    type="date"
                    value-format="YYYY-MM-DD HH:mm:ss"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="projectOrg"
                  label="立项机构"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.projectOrg"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="projectLevel"
                  label="立项级别"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.projectLevel"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="projectPrincipalPeople"
                  label="项目负责人"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.projectPrincipalPeople"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item label="主要推广人员" :key="Date.now()">
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.majorPromotePeople"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="placeInfo"
                  label="地点"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.placeInfo"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="startAndEndTime"
                  label="计划开竣工时间"
                >
                  <a-range-picker
                    disabled
                    v-model="queryParam.startAndEndTime"
                    type="date"
                    value-format="YYYY-MM-DD HH:mm:ss"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="scope"
                  label="规模"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.scope"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  label="证书编号"
                  :key="3"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.certificateCode"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
            </template>

            <!--                工法-->
            <template v-if="achievementsTypeName === '工法'">
              <a-col span="8">
                <a-form-model-item
                  prop="constructionCodeNo"
                  label="工法编号"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.constructionCodeNo"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="year"
                  label="年度"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.year"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="awardDpt"
                  label="授予单位"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.awardDpt"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
            </template>

            <!--                国家知识产权-专利-->
            <template v-if="completeAchievementsLevelName1 === '发明专利' || completeAchievementsLevelName1 === '实用新型专利'">
              <a-col span="8">
                <a-form-model-item
                  prop="patentNo"
                  label="专利号"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.patentNo"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="applyDay"
                  label="申请日"
                >
                  <a-date-picker
                    disabled
                    v-model="queryParam.applyDay"
                    type="date"
                    value-format="YYYY-MM-DD HH:mm:ss"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item label="公告日">
                  <a-date-picker
                    disabled
                    v-model="queryParam.announcementDay"
                    type="date"
                    value-format="YYYY-MM-DD HH:mm:ss"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="zone"
                  label="片区"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.zone"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item label="状态">
                  <a-select v-model="queryParam.teachStatus" disabled>
                    <a-select-option value="1">授权</a-select-option>
                    <a-select-option value="2">受理</a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>
            </template>

            <!--                国家知识产权-软著-->
            <template v-if="completeAchievementsLevelName1 === '计算机软件著作权'">
              <a-col span="8">
                <a-form-model-item
                  prop="registerNo"
                  label="登记号"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.registerNo"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="developmentCompletedDay"
                  label="开发完成日"
                >
                  <a-date-picker
                    disabled
                    v-model="queryParam.developmentCompletedDay"
                    type="date"
                    value-format="YYYY-MM-DD HH:mm:ss"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="publicationDay"
                  label="首次发表日"
                >
                  <a-date-picker
                    disabled
                    v-model="queryParam.publicationDay"
                    type="date"
                    value-format="YYYY-MM-DD HH:mm:ss"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="wayOfPower"
                  label="权利取得方式"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.wayOfPower"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="zone"
                  label="片区"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.zone"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
            </template>

            <!--                论文-->
            <template v-if="achievementsTypeName === '论文'">
              <a-col span="8">
                <a-form-model-item
                  prop="journal"
                  label="刊物"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.journal"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="year"
                  label="年度"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.year"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="periodsNum"
                  label="期数"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.periodsNum"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="paperSituation"
                  label="论文情况"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.paperSituation"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="leadAuthorJobTitle"
                  label="第一作者职称"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.leadAuthorJobTitle"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="leadAuthorPosition"
                  label="第一作者职务"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.leadAuthorPosition"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item
                  prop="leadAuthorSpecialty"
                  label="第一作者专业"
                >
                  <BaseInput
                    disabled
                    v-model.trim="queryParam.leadAuthorSpecialty"
                    placeholder="请输入"
                  />
                </a-form-model-item>
              </a-col>
            </template>

            <!--            科技成果评价-->
            <template v-if="achievementsTypeName === '科技成果评价'">
              <a-col span="8">
                <a-form-model-item prop="appraiseDate" label="鉴定（验收）年月">
                  <a-date-picker
                    disabled v-model="queryParam.appraiseDate" type="date"
                    value-format="YYYY-MM-DD HH:mm:ss"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item prop="presideAgency" label="主持机构">
                  <BaseInput disabled v-model="queryParam.presideAgency" placeholder="请输入" />
                </a-form-model-item>
              </a-col>
              <a-col span="24">
                <a-form-model-item prop="appraiseSummary" label="鉴定（验收）结论摘要">
                  <BaseInput disabled v-model="queryParam.appraiseSummary" placeholder="请输入" />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item prop="appraiseMember" label="鉴定（验收）主要成员">
                  <BaseInput disabled v-model="queryParam.appraiseMember" placeholder="请输入" />
                </a-form-model-item>
              </a-col>
            </template>

            <!--            科技查新-->
            <template v-if="achievementsTypeName === '科技查新'">
              <a-col span="8">
                <a-form-model-item prop="commissionDate" label="委托时间">
                  <a-date-picker disabled
                                 v-model="queryParam.commissionDate" type="date"
                                 value-format="YYYY-MM-DD HH:mm:ss"
                  />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item prop="reportCode" label="报告编号">
                  <BaseInput disabled v-model="queryParam.reportCode" placeholder="请输入" />
                </a-form-model-item>
              </a-col>
              <a-col span="8">
                <a-form-model-item prop="newAgency" label="查新机构">
                  <BaseInput disabled v-model="queryParam.newAgency" placeholder="请输入" />
                </a-form-model-item>
              </a-col>
              <a-col span="24">
                <a-form-model-item prop="findPurpose" label="查新目的">
                  <BaseInput disabled v-model="queryParam.findPurpose" placeholder="请输入" />
                </a-form-model-item>
              </a-col>
            </template>

            <!-- <a-col span="8">
              <a-form-model-item prop="completeOrgName" label="成果完成单位">
                <a-select disabled v-model="queryParam.completeOrgName" placeholder="请选择">
                  <a-select-option :value="item.name" v-for="item in completeOrgList">{{ item.name }}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col> -->
            <a-col span="16">
              <a-form-model-item label="备注">
                <BaseInput disabled v-model="queryParam.remark" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
            <a-col span="24">
              <a-form-model-item label="附件上传">
                <file-link :file-list="queryParam.fileArrays" />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </a-card>
      <div v-if="!isConsultation" class="page-btn-right-top">
        <a-button
          v-check-visible-in-detail
          style="margin: 0 10px"
          @click="$close"
        >
          关闭
        </a-button>
      </div>
    </div>

  </base-breadcrumb>
</template>

<script>
import { getDeclare, addComplete, titleLabelQuery } from '@/api/achievementsManage'
import { getClassifyList, getGradeList } from '@/api/achievementsType'
import Madel from '../plots/components/Madel'
import deleteFun from './delete.js'
import Model from '@/views/science/plots/components/Model'
import BaseEditPage from '@/views/baseEditPage'
import UploadList from '@/components/UploadList'
import SelectPerson from '@/components/Select/SelectPerson'

export default {
  extends: new BaseEditPage(),
  props: {
    idType: [Number, String],
    isAudit: {
      type: Boolean,
      default: false
    },
    // 是否作为意见征询
    isConsultation: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      queryParam: {
        beginAndEndTime: '',
        completionStatus: '4',
        completeEmployee: [],
        indexInfo: [],
        awardingUnit: '',
        achievementsNo: ''
      },
      completeOrgList: [
        { name: '中国建筑第八工程局有限公司', id: '1' },
        { name: '中国建筑第八工程局有限公司西南分公司', id: '2' },
        { name: '中建八局西南建设工程有限公司', id: '3' },
        { name: '中建八局两江建设工程有限公司', id: '4' },
        { name: '中建八局中南建设工程有限公司', id: '5' }
      ],
      Plan: null,
      declare: null,
      form: {
        viewName: ""
      },
      loading: false,
      ClassifyList: [],
      LevelList: [],
      indexInfoList: [],
      disabled: false,
      achievementsTypeName: '',
      completeAchievementsLevelName1: ''
    }
  },
  async mounted() {
    await this.getIndexInfoList()

    await this.getData()
  },
  methods: {
    async getIndexInfoList() {
      this.loading = true
      let res = await titleLabelQuery()
      this.loading = false
      if (res.code === this.SUCCESS_CODE) {
        this.indexInfoList = res.data
      }
    },
    getParam(url, name) {
      try {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
        var r = url.split('?')[1].match(reg)
        if (r != null) {
          return r[2]
        }
        return '' //如果此处只写return;则返回的是undefined
      } catch (e) {
        return '' //如果此处只写return;则返回的是undefined
      }
    },
    async getData() {
      const ID = this.id
      this.spinning = true
      let args = {}

      const IdType = this.getParam(decodeURIComponent(this.detailUrl), 'IdType')
      if (this.completeId) {
        args.completeId = this.completeId
      } else if (this.businessId) {
        let type = ['id', 'completeId', 'declareId'][IdType]
        console.log(type)
        args[type] = this.businessId
      } else {
        args.id = ID
      }

      this.loading = true
      let res1 = await getClassifyList({ status: '1' })
      if (res1.code === this.SUCCESS_CODE) {
        this.ClassifyList = res1.data
      }
      let res = await getDeclare(args)
      this.loading = false
      if (res.code === this.SUCCESS_CODE) {
        this.form = res.data
        this.form.viewName = this.form.branchCompany + '/' + this.form.projectName
        this.declare = res.data.sciencesDeclare
        this.Plan = res.data.sciencesPlan 
        this.queryParam = res.data.sciencesComplete || {
          completionStatus: '4',
          completeEmployee: [],
          awardingUnit: '',
          achievementsNo: '',
          beginAndEndTime: '',
          indexInfo: []
        }
        if (this.queryParam.indexInfo) {
          try {
            this.queryParam.indexInfo = JSON.parse(this.queryParam.indexInfo)
          }catch (e){
            this.queryParam.indexInfo = []
          }
        } else {
          this.queryParam.indexInfo = []
        }
        try {
          if (this.queryParam.startAndEndTime) {
            this.queryParam.startAndEndTime = JSON.parse(this.queryParam.startAndEndTime)
          }
        } catch (e) {
        }
        if (this.queryParam.completeEmployee) {
          this.queryParam.completeEmployee = this.queryParam.completeEmployee.map(v => {
            return { name: v.empName, id: v.empId,sortNum: v.sortNum }
          })
        }
        res.data.completeStatusNameCode && (this.queryParam.completionStatus = res.data.completeStatusNameCode.toString())
        this.queryParam.achievementsTypeId && await this.getLevelList(this.queryParam.achievementsTypeId, true)
        this.queryParam.completeAchievementsLevelId && this.completeAchievementsLevelIdChange(this.queryParam.completeAchievementsLevelId, true)
      }
    },
    async getLevelList(typeId, init = false) {
      if (!init) {
        this.$set(this.queryParam, 'completeAchievementsLevelId', '')
      }
      let temp = this.ClassifyList.find(v => v.id === typeId)
      if (temp) {
        this.achievementsTypeName = temp.name
      }
      let res = await getGradeList({ typeId: this.queryParam.achievementsTypeId, status: '1' })
      if (res.code === this.SUCCESS_CODE) {
        this.LevelList = res.data.data
      }
    },
    completeAchievementsLevelIdChange(e, init = false) {
      let temp = this.LevelList.find(v => v.id === e)
      if (temp) {
        this.completeAchievementsLevelName1 = temp.levelName
        if (!init) {
          this.queryParam.completeEmployee = []
        }
      }
    }

  },
  watch: {
    'queryParam.completionStatus'(e) {
      if (e === '4') {
        this.disabled = false
      } else if (e === '5') {
        this.disabled = true
        this.$set(this.queryParam, 'awardingUnit', '')
        this.$set(this.queryParam, 'achievementsNo', '')
      }
    }
  }
}
</script>
